package com.dayowa.consumer;

import com.dayowa.entity.MessageEntity;
import com.dayowa.repository.MessageRepository;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


@Component
public class KafkaConsumer {

    private final MessageRepository messageRepository;

    public KafkaConsumer(MessageRepository messageRepository) {
        this.messageRepository = messageRepository;
    }

    @KafkaListener(topics = "example-topic", groupId = "example-group")
    public void consume(String message) {
        MessageEntity entity = new MessageEntity();
        entity.setContent(message);
        messageRepository.save(entity);
        System.out.println("Message consumed: " + message);
    }
}
